package com.bjdd.jdy.ui.exam;

import com.bjdd.jdy.util.L;
import com.bjdd.jdy.util.T;

/**
 * Created by Administrator on 2017/4/13.
 */

public class ExamPresenter extends ExamContract.Presenter {
    @Override
    public void getExam(String token, String carrierId) {
        showLoadingDialog(false);
        rxManager.add(model.getExamModel(token,carrierId)
        .subscribe(result -> {
            hideLoadingDialog();
            if(!result.isError()){
                view.setView(result.getData());
            }else {
                T.show(result.getMsg());
            }
        },e -> {
            hideLoadingDialog();
            L.d("错误："+e.getMessage());
            T.show("获取题目失败");
        }));
    }

    @Override
    public void commitExam(String token,int chapter, String carrierId) {
        showLoadingDialog(false);
        rxManager.add(model.commitExam(token,chapter,carrierId)
        .subscribe(result -> {
            hideLoadingDialog();
            if (!result.isError()){
                view.passExam();
            }else {
                T.show(result.getMsg());
            }
        },e -> {
            hideLoadingDialog();
            T.show("提交失败");
        }));
    }

    @Override
    public void onStart() {

    }
}
